Ext.define('PJ.view.unitregistrationmanagement.UserUploadInfo', {
    extend: 'AM.default.DefaultWindowForm',
    
    width: 400,
    autoHeight: true,
    
    initComponent: function(){
    	var me = this;
        this.items = [{
        	xtype: "container",
        	layout: "column",
        	items:[{
            	xtype:"textfield",
            	fieldLabel: "请选择文件",
            	margin: '5 0 0 0',
            	labelWidth: 65,
				labelAlign:'right',
            	columnWidth: .7,
            	name: "aicc",
                emptyText:"请选择文件"
            }, {
            	margin: '5 0 0 5',
                border: false,
                width:28,
                height:24,
            	columnWidth:.1,
                itemId:"USUploadUserFile",
            	html: '<span id="USUploadUserFile"></span>'//浏览按钮的显示
            }, {
                xtype: 'button',
                text: '下载模板',
    			width : 80,
            	margin: '5 0 0 5',
                columnWidth: .2,
    			listeners : {
    				click : function() {
    					var atag = Ext.get("exportResume");
    					atag.set({
    						"href": me.downUrl
    					});
    					atag.dom.click();
    				}
    			}
            }, {
                xtype: 'label',
                html: '导入文件格式为.xls，并且为excel工作薄第一个表单',
                style: 'color:red;',
                margin: '5 0 0 45',
                columnWidth: 1
            }]
        }];
        this.buttons = [{
            text: '关闭',
            scope: this,
            handler: function(button, event){
				button.up('window').close();
            }
        }];
        this.callParent(arguments);
    },
    saveToken: function(){
        var form = this.down("form");
        Ext.Ajax.request({
            url: tokenUrl,
            success: function(response){
                var data = response.responseText;
                var token = Ext.decode(data, true);
                form.getForm().findField("springmvc.TOKEN").setValue(token);
            }
        });
    },
    
    listeners: {
    	afterrender:function(){
    		var win = this;
    		var form = win.down('form');
	        var baseForm = form.getForm();
    		this.loadMask = new Ext.LoadMask(this, {
                msg: "正在上传文件,请稍后...."
            });
    		var uploadfUrl = win.importUrl;
    		new SWFUpload(new uploadFiles("USUploadUserFile",gj_onlineLearning_constant.loadUrlStar,uploadfUrl,function(file){
					win.loadMask.show();
    				this.setPostParams({"searchClassId": win.classId});
    				baseForm.findField("aicc").setVisible(true).setValue(file.name);
    			}, function(file, serverData){
    				win.loadMask.hide();
    				serverData=JSON.parse(serverData);
    				if(serverData.success){
    					var msg = serverData.msg;
                        //msg = msg.replace(/\r\n/g, "<br />");
    					Ext.Msg.alert('信息', msg||"文件上传成功!",function(){
            				win.close();
    					});
    				}else{
    					var msg = serverData.msg||"文件上传失败!";
                        //msg = msg.replace(/\r\n/g, "<br />");
                        win1 = Ext.create("AM.default.DefaultWindowView", {
                            title: "提示",
                            width: 510,
                            height: 170,
                            items: [{
                                xtype: 'textareafield',
                                height: 100,
                                width: 488,
                                margin: '5 5 5 5',
                                value: msg,
                                readOnly: true
                            }],
                            buttons: [{
                                text: '确定',
                                handler: function(){
                            		win1.close();
                                    win.close();
                                }
                            }]
                        });
    				}
    			},"*.xls;*.xlsx"//,"aicc"
    		));
    	},
    	close: function(){
    		this.grid.store.load();
    	}
    }
});
